﻿using KLF.Lib.Browser.DOM.HTML;
namespace KLF.Lib.Browser.DOM.Events
{
    public class KeyboardEvent : Event
    {
        public KeyboardEvent(string type)
            : base(type)
        {
        }

        public KeyboardEvent(string type, object eventInit)
            : base(type, eventInit)
        {
        }

        public void initKeyboardEvent(
            string typeArg,
            bool canBubbleArg,
            bool cancelableArg,
            object viewArg,
            char charArg,
            char keyArg,
            int locationArg,
            string modifiersListArg,
            bool repeat,
            string localeArg)
        {
            switch (type = typeArg.ToLowerInvariant())
            {
                case HTMLConstants.HTML_EVENT_KEYDOWN:
                case HTMLConstants.HTML_EVENT_KEYPRESS:
                case HTMLConstants.HTML_EVENT_KEYUP:
                    cancelable = bubbles = true;
                    break;

                default:
                    cancelable = cancelableArg;
                    bubbles = canBubbleArg;
                    break;
            }

            altKey = metaKey = shiftKey = false;
            charCode = key = charArg;
            keyCode = keyArg;
            which = 0;
        }

        public bool altKey { get; internal set; }

        public char charCode { get; internal set; }

        public bool ctrlKey { get; internal set; }

        public string locale { get; internal set; }

        public int location { get; internal set; }

        public char key { get; internal set; }

        public char keyCode { get; internal set; }

        public bool metaKey { get; internal set; }

        public bool repeat { get; internal set; }

        public bool shiftKey { get; internal set; }

        public int which { get; internal set; }
    }
}
